﻿using System.Collections.Generic;
using Ewk.MachineLearning.Classification.Common;
using Ewk.MachineLearning.Classification.Interfaces;

namespace Ewk.MachineLearning.Persistance.Domain
{
    /// <summary>
    /// Represents a classification or a category.
    /// </summary>
    public class Category :
        TextEntity,
        ILinkedTextEntity
    {
        //private ICollection<WordForCategoryLink> _wordsForCategory;
        private ICollection<WordInCategoryLink> _wordsInCategory;

/*
        /// <summary>
        /// A link to a collection of <see cref="Word"/> instances that have been linked with this <see cref="Category"/>.
        /// </summary>
        public virtual ICollection<WordForCategoryLink> WordsForCategory
        {
            get { return _wordsForCategory ?? (_wordsForCategory = new List<WordForCategoryLink>()); }
            set { _wordsForCategory = value; }
        }
*/

        /// <summary>
        /// A link to a collection of <see cref="Word"/> instances that appear in this <see cref="Category"/>.
        /// </summary>
        public virtual ICollection<WordInCategoryLink> WordsInCategory
        {
            get { return _wordsInCategory ?? (_wordsInCategory = new List<WordInCategoryLink>()); }
            set { _wordsInCategory = value; }
        }

        #region Implementation of ILinkedTextEntity
        #region Implementation of IEntityEquatable<in ILinkedEntity>

        bool IEntityEquatable<ILinkedEntity>.EqualsForMachineLearning(ILinkedEntity other)
        {
            var comparer = new TextEntityComparer<ILinkedTextEntity>();
            return comparer.Equals(this, other as ILinkedTextEntity);
        }

        #endregion

        #region Implementation of ILinkedEntity

        IEnumerable<IFeatureLink> ILinkedEntity.Links
        {
            get { return WordsInCategory; }
        }

        void ILinkedEntity.AddLink(IFeatureLink link)
        {
            WordsInCategory.Add((WordInCategoryLink)link);
        }

        #endregion
        #endregion
    }
}